package cn.edu.sgu.www.mhxysy.controller.chongwu_shizhuang;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.dto.chongwu_shizhuang.ChongwuShizhuangDTO;
import cn.edu.sgu.www.mhxysy.entity.chongwu_shizhuang.ChongwuShizhuang;
import cn.edu.sgu.www.mhxysy.pager.Pager;
import cn.edu.sgu.www.mhxysy.restful.JsonPage;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.chongwu_shizhuang.ChongwuShizhuangService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "宠物时装管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/chongwu_shizhuang", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class ChongwuShizhuangController {

    private final ChongwuShizhuangService chongwuShizhuangService;

    @Autowired
    public ChongwuShizhuangController(ChongwuShizhuangService chongwuShizhuangService) {
        this.chongwuShizhuangService = chongwuShizhuangService;
    }

    @ApiOperation("计算评分")
    @RequestMapping(value = "/compute", method = RequestMethod.POST)
    public JsonResult<Void> compute(
            @ApiParam(name = "shizhuangId", value = "宠物时装ID", required = true)
            @NotBlank(message = CustomMessages.XINGSHI_ID_NOT_NULL) String shizhuangId) {
        chongwuShizhuangService.compute(shizhuangId);

        return JsonResult.success(CustomMessages.OPERATE_SUCCESS);
    }

    @ApiOperation("穿戴宠物时装")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "chongwuId", value = "宠物ID", required = true),
            @ApiImplicitParam(name = "shizhuangId", value = "宠物时装ID", required = true)
    })
    @RequestMapping(value = "/wear", method = RequestMethod.POST)
    public JsonResult<Void> wear(
            @NotBlank(message = CustomMessages.CHONGWU_ID_NOT_NULL) String chongwuId,
            @NotBlank(message = "宠物时装" + CustomMessages.ID_NOT_NULL) String shizhuangId) {
        chongwuShizhuangService.wear(chongwuId, shizhuangId);

        return JsonResult.success(CustomMessages.OPERATE_SUCCESS);
    }

    @ApiOperation("添加宠物时装")
    @ApiOperationSupport(ignoreParameters = "id")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public JsonResult<Void> insert(@Validated ChongwuShizhuangDTO chongwuShizhuangDTO) {
        chongwuShizhuangService.insert(chongwuShizhuangDTO);

        return JsonResult.success(CustomMessages.INSERT_SUCCESS);
    }

    @ApiOperation("通过ID删除宠物时装")
    @RequestMapping(value = "/deleteById", method = RequestMethod.POST)
    public JsonResult<Void> deleteById(
            @ApiParam(name = "id", value = "宠物时装ID", required = true)
            @NotBlank(message = CustomMessages.ID_NOT_NULL) String id) {
        chongwuShizhuangService.deleteById(id);

        return JsonResult.success(CustomMessages.DELETE_SUCCESS);
    }

    @ApiOperation("通过ID修改宠物时装信息 ")
    @RequestMapping(value = "/updateById", method = RequestMethod.POST)
    public JsonResult<Void> updateById(@Validated ChongwuShizhuangDTO chongwuShizhuangDTO) {
        chongwuShizhuangService.updateById(chongwuShizhuangDTO);

        return JsonResult.success(CustomMessages.UPDATE_SUCCESS);
    }

    @ApiOperation("查询全部宠物时装")
    @RequestMapping(value = "/selectAll", method = RequestMethod.GET)
    public JsonResult<List<ChongwuShizhuang>> selectAll() {
        List<ChongwuShizhuang> list = chongwuShizhuangService.selectAll();

        return JsonResult.success(null, list);
    }

    @ApiOperation("通过ID查询宠物时装")
    @RequestMapping(value = "/selectById", method = RequestMethod.GET)
    public JsonResult<ChongwuShizhuang> selectById(
            @ApiParam(name = "id", value = "宠物时装ID", required = true)
            @NotBlank(message = CustomMessages.ID_NOT_NULL) String id) {
        ChongwuShizhuang shizhuangCategory = chongwuShizhuangService.selectById(id);

        return JsonResult.success(null, shizhuangCategory);
    }

    @ApiOperation("通过宠物ID查询宠物时装列表")
    @RequestMapping(value = "/selectByChongwuId", method = RequestMethod.GET)
    public JsonResult<List<ChongwuShizhuang>> selectByChongwuId(
            @ApiParam(name = "chongwuId", value = "宠物类型ID", required = false)
            @RequestParam(required = false) Integer chongwuId) {
        List<ChongwuShizhuang> list = chongwuShizhuangService.selectByChongwuId(chongwuId);

        return JsonResult.success(null, list);
    }

    @ApiOperation("分页查询宠物时装列表")
    @RequestMapping(value = "/selectByPage", method = RequestMethod.GET)
    public JsonResult<JsonPage<ChongwuShizhuang>> selectByPage(Pager<ChongwuShizhuang> pager) {
        Page<ChongwuShizhuang> page = chongwuShizhuangService.selectByPage(pager);

        return JsonResult.restPage(page);
    }

}